import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { IonicPage } from 'ionic-angular/navigation/ionic-page';
import { AppGlobal } from '../../app/app.global';
import { TranslateService } from '@ngx-translate/core';
import { Tabs } from 'ionic-angular';

@IonicPage()
@Component({
  selector: 'page-mine',
  templateUrl: 'mine.html'
})
export class MinePage {
  language:any;
  constructor(public navCtrl: NavController,public translate:TranslateService,public tabs:Tabs) {
    this.language = AppGlobal.getLanguage();
  }

  /**
   * 选择语言
   * 选择之后设置页面语言 并且（更新用户选择记住当前选择）
   */
  changeLanguage(){
    if(this.translate != this.language.value){
      console.log(this.translate.currentLang+">>修改语言>>"+this.language.value);
      this.translate.use(this.language.value);
    }
    
  }

  toHome(){
    this.tabs.select(0);
  }

  /**
   * 跳转到login page页面
   */
  login(){
   this.navCtrl.push("LoginPage")
  }

  toUserDetails(){
    this.navCtrl.push("UserDetailsPage");
  }





    //ionic中当页面进入初始化的时候触发的生命周期方法
    ionViewWillEnter() {
      let elements = document.querySelectorAll(".tabbar");
      if (elements != null) {
        Object.keys(elements).map((key) => {
          elements[key].style.display = 'none';
        });
      }
  
    }
  
    ionViewWillLeave() {
      let elements = document.querySelectorAll(".tabbar");
      if (elements != null) {
        Object.keys(elements).map((key) => {
          elements[key].style.display = 'flex';
        });
      }
    }

}
